package com.loveprogrammer.eternity.service;

import com.loveprogrammer.eternity.action.BaseAction;
import com.loveprogrammer.eternity.enums.EquipmentEnum;
import com.loveprogrammer.eternity.model.game.HeroWrapper;
import com.loveprogrammer.eternity.model.product.Equipment;
import com.loveprogrammer.eternity.model.product.FallingGoodsCalculator;
import com.loveprogrammer.eternity.utils.ScannerInput;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0.0
 * @description: 赌场服务
 * @author: eric
 * @date: 2022-12-09 13:53
 **/
public class CasinoService extends BaseAction {

    private static Map<Integer,Integer> map = new HashMap<>();

    static {
        map.put(1,500);
        map.put(2,1000);
        map.put(3,2000);
        map.put(4,5000);
        map.put(5,10000);
        map.put(6,16000);
        map.put(7,25000);
    }

    public static void gamble(HeroWrapper heroWrapper){

        eventManager.notifyMessage("欢迎来到赌场，赌博武器概率获得词缀，有小概率获得套装",1);
        // 选择要赌博的位置
        int modulus = (int) (heroWrapper.getHero().getLevel() * 1.0/5) + 1;
        eventManager.notifyMessage("请选择要赌博的装备 最少需要" + modulus * 500 + "金币 退出",1);
        if(heroWrapper.getWarehouse().getGoldCoin() < 500){
            eventManager.notifyMessage("穷鬼，没钱还来赌场，快滚",1);
            return;
        }
        for (int i = 1; i <= EquipmentEnum.total; i++) {
            eventManager.notifyPrompt("【" + i + ":" + EquipmentEnum.getByPosNum(i).getDesc() + "】 ");
            if(i%7 == 0){
                eventManager.notifyPrompt("\n");
            }
        }
        int choose = ScannerInput.inputInt(1, EquipmentEnum.total, 0);
        while (choose != 0) {
            EquipmentEnum equipmentEnum = EquipmentEnum.getByPosNum(choose);
            // 不同的金币赌博效果不同
            eventManager.notifyMessage("请选择你要下注的金额",1);
            eventManager.notifyMessage("1、" + 500 * modulus + " 小概率获得蓝色进阶装备",1);
            eventManager.notifyMessage("2、"+1000*modulus+" 大概率获得蓝色进阶装备，小概率获得黄色优质装备",1);
            eventManager.notifyMessage("3、"+2000*modulus+" 大概率获得黄色优质装备，小概率获得紫色卓越装备",1);
            eventManager.notifyMessage("4、"+5000*modulus+" 大概率获得紫色卓越装备，小概率获得红色传奇装备",1);
            eventManager.notifyMessage("5、"+10000*modulus+" 中等概率获得红色传奇装备，小概率获得暗金史诗装备",1);
            eventManager.notifyMessage("6、"+16000*modulus+" 大概率获得红色传奇装备，中概率获得暗金史诗装备",1);
            eventManager.notifyMessage("7、"+25000*modulus+" 中等概率获得暗金史诗装备，小概率获得绿色套装装备",1);
            eventManager.notifyMessage("请选择你要下注的选项 0 放弃",1);

            choose = ScannerInput.inputInt(1, 7, 0);
            if(choose == 0){
                break;
            }
            int cost = map.get(choose) * modulus;
            if(heroWrapper.getWarehouse().getGoldCoin() < cost){
                eventManager.notifyMessage("穷鬼，没钱还来赌场，快滚",1);
                break;
            }
            // 获得一个可以穿的对应装备
            FallingGoodsCalculator calculator = new FallingGoodsCalculator();
            Equipment equipment = calculator.getCasinoEquipmentByHero(heroWrapper.getHero(), choose, equipmentEnum);
            if(equipment != null){
                heroWrapper.getWarehouse().getEquipmentList().add(equipment);
                heroWrapper.getHero().tryToWearAndSale(equipment);
                eventManager.notifyMessage("获得装备" + equipment.prettyPrint(),1);
                heroWrapper.getWarehouse().setGoldCoin(heroWrapper.getWarehouse().getGoldCoin() - cost);
                heroWrapper.getGameStatus().setCasinoTimes(heroWrapper.getGameStatus().getCasinoTimes() + 1);
            }else{
                eventManager.notifyMessage("没有适合的装备",1);
            }

            // 继续赌博
            eventManager.notifyMessage("请选择要赌博的装备,0 退出",1);
            for (int i = 1; i <= EquipmentEnum.total; i++) {
                eventManager.notifyPrompt("【" + i + ":" + EquipmentEnum.getByPosNum(i).getDesc() + "】 ");
                if(i%7 == 0){
                    eventManager.notifyPrompt("\n");
                }
            }
            choose = ScannerInput.inputInt(1, EquipmentEnum.total, 0);
        }
    }


}
